package com.fxpc.hddc.disaster.jpa.dao.pg;


import com.fxpc.hddc.disaster.dto.pg.entity.YhDisasterPgEntity;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.time.LocalDate;
import java.util.List;

@Repository
public interface YhDisasterPgBaseDao extends JpaRepository<YhDisasterPgEntity, String> {

    @Query(nativeQuery = true, value = "select * from yh_disaster_fw WHERE is_valid='1' ")
    List<YhDisasterPgEntity> findFwAllTime();

    @Query(nativeQuery = true, value = "select * from yh_disaster_fw WHERE CAST(create_time AS  DATE)= DATE(:nowDay) AND is_valid='1' ")
    List<YhDisasterPgEntity> findFwPgOneDayDataByCreateTime(@Param(value = "nowDay") LocalDate nowDay);


    @Query(nativeQuery = true, value = "select * from yh_disaster_sz WHERE is_valid='1'")
    List<YhDisasterPgEntity> findSzAllTime();

    @Query(nativeQuery = true, value = "select * from yh_disaster_sz WHERE CAST(create_time AS  DATE)= DATE(:nowDay) AND is_valid='1'")
    List<YhDisasterPgEntity> findSzPgOneDayDataByCreateTime(@Param(value = "nowDay") LocalDate nowDay);


    @Query(nativeQuery = true, value = "select * from yh_disaster_cs WHERE is_valid='1'")
    List<YhDisasterPgEntity> findCsAllTime();

    @Query(nativeQuery = true, value = "select * from yh_disaster_cs WHERE CAST(create_time AS  DATE)= DATE(:nowDay) AND is_valid='1' ")
    List<YhDisasterPgEntity> findCsPgOneDayDataByCreateTime(@Param(value = "nowDay") LocalDate nowDay);


    Long count(Specification<YhDisasterPgEntity> specification);
}
